Extracting the mean profile is based on the really nice paper by Chu et al (2010).

## Loading required package: tools
## Loading required package: XML
## 
## Attaching package: 'XML'
## The following object is masked from 'package:tools':
## 
##     toHTML
## Loading required package: rgl
## Loading required package: shiny
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

## Saving 7 x 5 in image

## Saving 7 x 5 in image

## 
## Call:
## lm(formula = twist ~ x, data = subset(dframe, between(x, 220, 
##     600)))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.5841 -2.3916 -0.3183  1.7789 14.9651 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 85.966571   0.841485  102.16   <2e-16 ***
## x           -0.067643   0.001982  -34.14   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.407 on 242 degrees of freedom
## Multiple R-squared:  0.828,  Adjusted R-squared:  0.8273 
## F-statistic:  1165 on 1 and 242 DF,  p-value: < 2.2e-16

## Saving 7 x 5 in image

## Saving 7 x 5 in image

in black: average of all, in blue average based on profiles below 500, in green average based on profiles below 300, in red profile at 100.